//
//  GYStatusCell.swift
//  Weibo
//
//  Created by vane on 16/8/13.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit
import SnapKit
class GYStatusCell: UITableViewCell {
    
    var bottomViewTopConstraint: Constraint?
    
    var statusViewModel: GYStatusViewModel?{
        didSet{
            // 原创微博
            originalView.statusViewModel = statusViewModel
            //转发微博
//            retweetView.statusViewModel = statusViewModel
            
//            // 01 卸载约束
            bottomViewTopConstraint?.uninstall()
//
            if statusViewModel?.statusModel?.retweeted_status == nil{
//
                bottomView.snp_updateConstraints(closure: { (make) -> Void in
                   bottomViewTopConstraint = make.top.equalTo(originalView.snp_bottom).constraint

                })
                retweetView.hidden = true
            }else{

                retweetView.statusViewModel = statusViewModel

                bottomView.snp_updateConstraints(closure: { (make) -> Void in
                   bottomViewTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint

                })
                retweetView.hidden = false

                
            }
            bottomView.statusViewModel = statusViewModel
            
            
        }
    }


    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
        backgroundColor = RGB(237, green: 237, blue: 237)
        
        contentView.addSubview(originalView)
        contentView.addSubview(retweetView)
        contentView.addSubview(bottomView)
        
        originalView.snp_makeConstraints { (make) -> Void in
            make.leading.top.trailing.equalTo(contentView)
//            make.height.equalTo(100)
        }
        
        retweetView.snp_makeConstraints { (make) -> Void in
            
            make.leading.trailing.equalTo(contentView)
            make.top.equalTo(originalView.snp_bottom)
        }
        
        bottomView.snp_makeConstraints { (make) -> Void in
            
            make.leading.bottom.trailing.equalTo(contentView)
            
          bottomViewTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
            
            make.height.equalTo(35)
        }

        contentView.snp_makeConstraints { (make) -> Void in
            make.leading.top.trailing.equalTo(self)
            make.bottom.equalTo(bottomView)
        }
    }
    
    private lazy var originalView: GYStatusOriginalView = GYStatusOriginalView()
    
    private lazy var retweetView:GYStatusRetweetView = GYStatusRetweetView()
    
    private lazy var bottomView: GYStatusBottomView = GYStatusBottomView()
}
